<?php
/**
 * Haozhaoya!
 * Copyright (c) 2009-2011 http://www.haozhaoya.com All Right Reserved!
 * Author:KeelDo <keeldo@keeldo.com> 
 */
class SchoolModel extends Model{
	protected $_map=array(
		'i5fc7164b3db822f37d21fb80cc92049b'=>'school_id',
		'i2628daca0e6e5df8841ca4e4f0575890'=>'school_name',
		'i2da79a6db84c717acbc1b6a3076932b4'=>'school_abbr',
		'i2b4765503348482c374e80f5d1b4e9ec'=>'school_weburl',
		'i22e22ba8c58848eb1cdb6e8e38dcd79d'=>'school_open',
		'i7e53343224f790fc915e30e55b92759c'=>'school_admin_userid',
		'ifbacb57ed563c6cee9080fabffbb3c7c'=>'school_admin_username',
		'i113f36158781e4bbab6ab42152d65d4c'=>'school_cityname',
		'i8ebb90b893d07d7d39c136837cd1cd79'=>'school_cityid',
		'i2da2632681dc3f7319638fbb70688ca4'=>'school_provincename',
		'i23901e78bf779a04b0843129bb45f0b8'=>'school_provinceid',
		'i602bfa6091c33155566df6bca43f3db7'=>'school_campus',
	);
	protected $fields=array(
		'school_id',
		'school_name',
		'school_abbr',
		'school_weburl',
		'school_open',
		'school_admin_userid',
		'school_admin_username',
		'school_cityname',
		'school_cityid',
		'school_provincename',
		'school_provinceid',
		'school_campus',
        
        '_pk'=>'school_id',
        '_autoinc'=>true,
	);
    
    public function getByAbbr($abbr){
        return $this->where("school_abbr='{$abbr}'")->find();
    }
    
    public function getByCityId($cid){
        return $this->where("school_cityid='{$cid}'")->select();
    }
    
    public function getCitys($provinceid,$filtCity=''){
        
        $str="SELECT distinct school_cityname,school_cityid,count(school_cityid) s_count FROM __TABLE__  WHERE school_provinceid='{$provinceid}'";
        if($filtCity) $str.=" AND school_cityid != '{$filtCity}'";
        $str.=" GROUP BY school_cityname";
        return $this->query($str);    
    }
    
}
?>